package com.yuan.springcloud.consumer;

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.stereotype.Component;

/**
 * Stream消息监听处理
 * @author YouYuan
 * @date 2020/4/6 2:12
 */
@Component
@EnableBinding(Sink.class)
public class MessageListener {

    /**
     * 监听binding中的消息
     * @param message
     */
    @StreamListener(Sink.INPUT)
    public void input(Object message) {
        //Stream接受到的消息都是被序列化成了String类型
        String className = message.getClass().getName();
        System.out.println("获取到[" + className + "]消息：" + message);
    }
}
